﻿using Appliaction.Dto.Pinv;
using Appliaction.IAppServices.IVendorService;
using Domain.Entitys.Pinv;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers.Pinv
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        private readonly IVendorService vendorService;

        public ValuesController(IVendorService vendorService)
        {
            this.vendorService = vendorService;
        }
        /// <summary>
        /// 分页、条件查询
        /// </summary>
        /// <param name="Vendor_name"></param>
        /// <param name="Vendor_code"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult Pinv_VendorFYWhere(string? Vendor_name, string? Vendor_code, int currentPage, int pageSize)
        {
            return new JsonResult(vendorService.Pinv_VendorFYWhere(Vendor_name, Vendor_code, currentPage, pageSize));
        }
        /// <summary>
        /// 查询总条数
        /// </summary>
        /// <param name="Vendor_name"></param>
        /// <param name="Vendor_code"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult Pinv_VendorCount(string? Vendor_name, string? Vendor_code)
        {
            return new JsonResult(vendorService.Pinv_VendorCount(Vendor_name, Vendor_code));
        }
        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="vendor"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Pinv_VendorAdd(VendorAddDto vendor)
        {
            var result = await vendorService.Pinv_VendorAdd(vendor);
            return Ok(result);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="vendor"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Pinv_VendorDelete(VendorDeleteDto vendor)
        {
            return new JsonResult(await vendorService.Pinv_VendorDelete(vendor));
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="vendor"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> Pinv_VendorUpdate(VendorUpdateDto vendor)
        {
            var result = await vendorService.Pinv_VendorUpdate(vendor);
            return Ok(result);
        }
        [HttpGet]
        public async Task<IActionResult> Pinv_VendorWhere(string? Vendor_name)
        {
            var result = await vendorService.Pinv_VendorWhere(Vendor_name);
            return Ok(result);
        }
    }
}
